iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 1
5
Software Development

以Postgresql為主,聊聊資料庫.系列 第 1

先來個月亮月餅煙火圖吧

  • 分享至 

  • xImage
  •  
WITH centers AS (
SELECT angle
     , len
     , ROUND(len * SIN(2 * PI() * angle)) AS x
     , ROUND(len * COS(2 * PI() * angle)) AS y
     , ROUND(len * 0.3)::INTEGER + 1 AS trace
  FROM (SELECT RANDOM() AS angle
             , 8 * (1 - POWER(RANDOM(), 3)) AS len
          FROM generate_series (1, 50) s
        ) q
),
traces AS (
SELECT *
     , generate_series(1, trace) AS part
  FROM centers
),
parts AS (
SELECT CASE
        WHEN trace = part THEN
         LEAST(len * 0.2, 2)::INTEGER
        ELSE
          TRUNC(angle * 8 - 0.5)::INTEGER % 4 + 3
       END AS symbol
     , TRUNC(x + part * SIN(2 * PI() * angle)) AS x
     , TRUNC(y + part * COS(2 * PI() * angle)) AS y
  FROM traces
)
SELECT ARRAY_TO_STRING(ARRAY(
       SELECT COALESCE((
              SELECT SUBSTR('.??\\-/|', MIN(symbol) + 1, 1)
                FROM parts
               WHERE x = col - 14
                 AND y = row - 12
              ), ' ')
         FROM generate_series(1, 25) col
        ), '') AS FIREWORKS
   FROM generate_series(1, 24) row;

result:
https://ithelp.ithome.com.tw/upload/images/20190916/2005064783ODa6iPP8.png

上面的SQL Command中使用了emoji,貼的時候有正常顯示,發表時變成問號了...
不過沒關係, 若要複製時,可以自行修正. 到以下網址,可以複製.
https://emojipedia.org/moon-cake/
https://emojipedia.org/full-moon-symbol/


下一篇
Postgresql 一些基本資料的查詢方式
系列文
以Postgresql為主,聊聊資料庫.31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言